package migrations

import (
	"github.com/goravel/framework/contracts/database/schema"
	"github.com/goravel/framework/facades"
)

type M20250303153206CreateSystemConfigTabTables struct {
}

// Signature The unique signature for the migration.
func (r *M20250303153206CreateSystemConfigTabTables) Signature() string {
	return "20250303153206_create_system_config_tab_tables"
}

// Up Run the migrations.
func (r *M20250303153206CreateSystemConfigTabTables) Up() error {
	if !facades.Schema().HasTable("system_config_tab_tables") {
		facades.Schema().Create("system_config_tab_tables", func(table schema.Blueprint) {
			table.ID()
			table.UnsignedBigInteger("pid")
			table.String("title")
			table.String("eng_title")
			table.TinyInteger("status").Default(0)
			table.String("icon").Default("")
			table.Enum("cfg_type", []any{1, 2, 3}).Default(1)
			table.SmallInteger("sort").Default(0)
			table.UnsignedBigInteger("menu_id").Nullable()
			table.SoftDeletes("deleted_at")
			table.Timestamps()
		})
	}
	if !facades.Schema().Connection("school").HasTable("system_config_tab_tables") {
		facades.Schema().Connection("school").Create("system_config_tab_tables", func(table schema.Blueprint) {
			table.ID()
			table.UnsignedBigInteger("pid")
			table.String("title")
			table.String("eng_title")
			table.TinyInteger("status").Default(0)
			table.String("icon").Default("")
			table.Enum("cfg_type", []any{1, 2, 3}).Default(1)
			table.SmallInteger("sort").Default(0)
			table.UnsignedBigInteger("menu_id").Nullable()
			table.SoftDeletes("deleted_at")
			table.Timestamps()
		})
	}
	if !facades.Schema().Connection("hospital").HasTable("system_config_tab_tables") {
		facades.Schema().Connection("hospital").Create("system_config_tab_tables", func(table schema.Blueprint) {
			table.ID()
			table.UnsignedBigInteger("pid")
			table.String("title")
			table.String("eng_title")
			table.TinyInteger("status").Default(0)
			table.String("icon").Default("")
			table.Enum("cfg_type", []any{1, 2, 3}).Default(1)
			table.SmallInteger("sort").Default(0)
			table.UnsignedBigInteger("menu_id").Nullable()
			table.SoftDeletes("deleted_at")
			table.Timestamps()
		})
	}

	return nil
}

// Down Reverse the migrations.
func (r *M20250303153206CreateSystemConfigTabTables) Down() error {
	facades.Schema().DropIfExists("system_config_tab_tables")
	facades.Schema().Connection("hospital").DropIfExists("system_config_tab_tables")
	facades.Schema().Connection("school").DropIfExists("system_config_tab_tables")
	return nil
}
